<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>后台系统</title>
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="/css/my-style.css">
</head>

<body>
<div class="kit-doc">
    <div class="layui-row">
        <div class="layui-col-md12 layui-card">
            <div class="layui-card-header"><i class="fa fa-bars"></i>&nbsp;修改密码</div>
            <div class="layui-form" action="" style="margin-top: 20px;">

                <div class="layui-form-item">
                    <label class="layui-form-label">旧密码</label>
                    <div class="layui-input-inline">
                        <input type="password" name="oldPassword" required lay-verify="required"
                               placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">6到20个字符</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">新密码</label>
                    <div class="layui-input-inline">
                        <input type="password" name="newPassword" required lay-verify="required"
                               placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">6到20个字符</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">确认新密码</label>
                    <div class="layui-input-inline">
                        <input type="password" name="newPassword2" required lay-verify="required"
                               placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>


<script src="/plugins/layui/layui.js"></script>
<!-- 表单 -->
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form,
            $ = layui.$,
            layer = layui.layer,
            laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //监听提交
        form.on('submit(formDemo)', function (data) {
            $.ajax({
                type: 'PUT',
                url: "/system/user/password",
                data: data.field,
                success: function (res) {
                    layer.closeAll();
                    if (res.code == 0) {
                        layer.msg("修改成功",{
                            time: 800
                        },function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            window.parent.location = "/logout";
                        });
                    } else {
                        layer.msg("修改失败" + data.msg);
                    }
                }
            });
            return false;
        });

    });

</script>

</body>

</html>